<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"emoh.xyz","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="修改主库参数  123456789101112alter system set db_unique_name&#x3D;&#39;etyyhis&#39; scope&#x3D;both sid&#x3D;&#39;*&#39;;alter system set log_archive_config&#x3D;&#39;dg_config&#x3D;(etyyhis,etyyhisdg)&#39; scope&#x3D;both sid&#x3D;&#39;*&#39;;alter system set log_archive">
<meta property="og:type" content="article">
<meta property="og:title" content="ORACLE 11G DataGuard 安装部署">
<meta property="og:url" content="http://emoh.xyz/2020/05/27/2019-07-17-ORACLE%2011G%20DataGuard%20%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/index.html">
<meta property="og:site_name" content="Just do it!">
<meta property="og:description" content="修改主库参数  123456789101112alter system set db_unique_name&#x3D;&#39;etyyhis&#39; scope&#x3D;both sid&#x3D;&#39;*&#39;;alter system set log_archive_config&#x3D;&#39;dg_config&#x3D;(etyyhis,etyyhisdg)&#39; scope&#x3D;both sid&#x3D;&#39;*&#39;;alter system set log_archive">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-05-27T02:14:16.026Z">
<meta property="article:modified_time" content="2020-05-28T03:33:44.740Z">
<meta property="article:author" content="Emoh">
<meta property="article:tag" content="oracle 安装部署">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://emoh.xyz/2020/05/27/2019-07-17-ORACLE%2011G%20DataGuard%20%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>ORACLE 11G DataGuard 安装部署 | Just do it!</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Just do it!</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://emoh.xyz/2020/05/27/2019-07-17-ORACLE%2011G%20DataGuard%20%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/touxiang.png">
      <meta itemprop="name" content="Emoh">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Just do it!">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          ORACLE 11G DataGuard 安装部署
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-05-27 10:14:16" itemprop="dateCreated datePublished" datetime="2020-05-27T10:14:16+08:00">2020-05-27</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-05-28 11:33:44" itemprop="dateModified" datetime="2020-05-28T11:33:44+08:00">2020-05-28</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/oracle-%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/" itemprop="url" rel="index"><span itemprop="name">oracle 安装配置</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <ol>
<li>修改主库参数</li>
</ol>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">alter</span> <span class="keyword">system</span> <span class="keyword">set</span> db_unique_name=<span class="string">'etyyhis'</span> <span class="keyword">scope</span>=<span class="keyword">both</span> <span class="keyword">sid</span>=<span class="string">'*'</span>;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">system</span> <span class="keyword">set</span> log_archive_config=<span class="string">'dg_config=(etyyhis,etyyhisdg)'</span> <span class="keyword">scope</span>=<span class="keyword">both</span> <span class="keyword">sid</span>=<span class="string">'*'</span>;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">system</span> <span class="keyword">set</span> log_archive_dest_1=<span class="string">'location=+DGRECOVER valid_for=(all_logfiles,all_roles) db_unique_name=etyyhis'</span> <span class="keyword">scope</span>=<span class="keyword">both</span> <span class="keyword">sid</span>=<span class="string">'*'</span>;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">system</span> <span class="keyword">set</span> log_archive_dest_2=<span class="string">'service=etyyhisdg lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=etyyhisdg'</span> <span class="keyword">scope</span>=<span class="keyword">both</span> <span class="keyword">sid</span>=<span class="string">'*'</span>;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">system</span> <span class="keyword">set</span> log_archive_dest_2=<span class="string">'service=etyyhisdg lgwr sync valid_for=(online_logfiles,primary_role) db_unique_name=etyyhisdg'</span> <span class="keyword">scope</span>=<span class="keyword">both</span> <span class="keyword">sid</span>=<span class="string">'*'</span>; <span class="comment">#最高可用模式</span></span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">system</span> <span class="keyword">set</span> log_archive_max_processes=<span class="number">6</span> <span class="keyword">scope</span>=<span class="keyword">both</span> <span class="keyword">sid</span>=<span class="string">'*'</span>;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">system</span> <span class="keyword">set</span> fal_server=<span class="string">'etyyhisdg'</span> <span class="keyword">scope</span>=<span class="keyword">both</span> <span class="keyword">sid</span>=<span class="string">'*'</span>;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">system</span> <span class="keyword">set</span> fal_client=<span class="string">'etyyhis'</span> <span class="keyword">scope</span>=<span class="keyword">both</span> <span class="keyword">sid</span>=<span class="string">'*'</span>;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">system</span> <span class="keyword">set</span> standby_file_management=<span class="keyword">auto</span> <span class="keyword">scope</span>=<span class="keyword">both</span> <span class="keyword">sid</span>=<span class="string">'*'</span>;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">system</span> <span class="keyword">set</span> db_file_name_convert=<span class="string">'+DGDATA'</span>,<span class="string">'+DGDATA'</span> <span class="keyword">scope</span>=<span class="keyword">spfile</span> <span class="keyword">sid</span>=<span class="string">'*'</span>; <span class="comment">#参数需要重启生效，用于备库文件路径转换</span></span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">system</span> <span class="keyword">set</span> log_file_name_convert=<span class="string">'+DGDATA'</span>,<span class="string">'+DGDATA'</span> <span class="keyword">scope</span>=<span class="keyword">spfile</span> <span class="keyword">sid</span>=<span class="string">'*'</span>; <span class="comment">#参数需要重启生效，用于备库文件路径转换</span></span><br><span class="line">SQL&gt; alter database force logging;</span><br></pre></td></tr></table></figure>



<ol start="2">
<li>修改监听和TNSNAME</li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line">etyyhis =</span><br><span class="line"> (DESCRIPTION =</span><br><span class="line">   (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.240.10)(PORT = 1521))</span><br><span class="line">   (CONNECT_DATA =</span><br><span class="line">     (SERVER = DEDICATED)</span><br><span class="line">     (SERVICE_NAME = etyyhis)</span><br><span class="line">   )</span><br><span class="line"> )</span><br><span class="line">etyyhisdg =</span><br><span class="line"> (DESCRIPTION =</span><br><span class="line">   (ADDRESS = (PROTOCOL = TCP)(HOST=172.16.240.20)(PORT = 1521))</span><br><span class="line">   (CONNECT_DATA =</span><br><span class="line">     (SERVER = DEDICATED)</span><br><span class="line">     (SERVICE_NAME = etyyhisdg)</span><br><span class="line">     (SID=etyyhis)</span><br><span class="line">         (UR=A)</span><br><span class="line">   )</span><br><span class="line">)</span><br><span class="line">etyyhis1 =</span><br><span class="line"> (DESCRIPTION =</span><br><span class="line">   (ADDRESS = (PROTOCOL = TCP)(HOST=172.16.240.8)(PORT = 1521))</span><br><span class="line">   (CONNECT_DATA =</span><br><span class="line">     (SERVER = DEDICATED)</span><br><span class="line">     (SERVICE_NAME = etyyhis)</span><br><span class="line">     (SID=etyyhis1)</span><br><span class="line">   )</span><br><span class="line"> )</span><br><span class="line">etyyhis2 =</span><br><span class="line"> (DESCRIPTION =</span><br><span class="line">   (ADDRESS = (PROTOCOL = TCP)(HOST=172.16.240.9)(PORT = 1521))</span><br><span class="line">   (CONNECT_DATA =</span><br><span class="line">     (SERVER = DEDICATED)</span><br><span class="line">     (SERVICE_NAME = etyyhis)</span><br><span class="line">     (SID=etyyhis2)</span><br><span class="line"> )</span><br><span class="line"> )</span><br></pre></td></tr></table></figure>

<ol start="3">
<li>拷贝PFILE ，密码文件到备库,创建备库文件系统</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">[oracle@ora-lab2 /u01/app/product/11.2.0/oracle]%mkdir fast_recovery_area</span><br><span class="line">[oracle@ora-lab2 /u01/app/product/11.2.0/oracle]%mkdir -p ./oradata/oraclebird</span><br><span class="line">[oracle@ora-lab2 /u01/app/product/11.2.0/oracle]%mkdir -p ./diag/rdbms/etyyhis/etyyhis</span><br><span class="line">[oracle@ora-lab2 /u01/app/product/11.2.0/oracle]%<span class="built_in">cd</span> ./diag/rdbms/etyyhis/etyyhis</span><br><span class="line">[oracle@ora-lab2 /u01/app/product/11.2.0/oracle/diag/rdbms/oraclebird/oraclebird]%mkdir alert  cdump  hm  incident  incpkg  ir  lck  metadata  metadata_dgif  metadata_pv  stage  sweep  trace</span><br><span class="line">[oracle@ora-lab2 /u01/app/product/11.2.0/oracle]%mkdir -p ./admin/etyyhis/</span><br><span class="line">[oracle@ora-lab2 /u01/app/product/11.2.0/oracle/admin/oraclebird]%mkdir adump  dpdump  pfile</span><br></pre></td></tr></table></figure>

<ol start="4">
<li>修改备库参数</li>
</ol>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">*.db_unique_name=etyyhisdg</span><br><span class="line">*.log_archive_config='dg_config=(etyyhis,etyyhisdg)'</span><br><span class="line">*.log_archive_dest_1='location=+DGRECOVER  valid_for=(all_logfiles,all_roles) db_unique_name=etyyhisdg'</span><br><span class="line">*.log_archive_dest_2='service=etyyhis lgwr async valid_for=(online_logfiles,primary_role)  db_unique_name=etyyhis'</span><br><span class="line">*.log_archive_max_processes=6</span><br><span class="line">*.fal_server='etyyhis'</span><br><span class="line">*.fal_client='etyyhisdg'</span><br><span class="line">*.standby_file_management=auto</span><br><span class="line">*.db_file_name_convert='+DGDATA','+DGDATA'</span><br><span class="line">*.log_file_name_convert='+DGDATA','+DGDATA'</span><br></pre></td></tr></table></figure>

<ol start="5">
<li>备份主库，恢复备库</li>
</ol>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">mkdir /u01/rman</span><br><span class="line">rman target /</span><br><span class="line">RMAN&gt; backup database format '/u01/rman/db_%d_%s_%p_%u_%T.dbf';</span><br><span class="line">RMAN&gt; sql 'alter system archive log current';</span><br><span class="line">RMAN&gt; backup archivelog all format '/u01/rman/arc_%d_%s_%p_%u_%T.arc';</span><br><span class="line">RMAN&gt;backup current controlfile for standby format '/u01/rman/ctl_sty__%d_%s_%p_%u_%T.dbf';</span><br><span class="line">rman target /</span><br><span class="line">RMAN&gt; startup nomount;</span><br><span class="line">RMAN&gt;restore controlfile from '/u01/rman/ctl_sty__ETYYHIS_10_1_0aqahqmh_20150627.dbf';</span><br><span class="line">RMAN&gt;sql 'alter database mount';</span><br><span class="line">RMAN&gt; list backup;</span><br><span class="line">RMAN&gt; restore database;</span><br><span class="line">RMAN&gt; recover database;</span><br><span class="line">RMAN&gt; exit</span><br></pre></td></tr></table></figure>

<ol start="6">
<li>添加主备库standby logfile</li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">查看当前在线日志情况</span><br><span class="line"><span class="keyword">select</span> inst_id,<span class="keyword">count</span>(<span class="number">1</span>),<span class="keyword">max</span>(<span class="keyword">bytes</span>) <span class="keyword">from</span> gv$<span class="keyword">log</span> <span class="keyword">group</span> <span class="keyword">by</span> inst_id;</span><br><span class="line">备库</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">add</span> <span class="keyword">standby</span> <span class="keyword">logfile</span> <span class="keyword">group</span> <span class="number">5</span> (<span class="string">'+DGDATA/etyyhis/standbylog/standby_group_05.log'</span>) <span class="keyword">size</span> <span class="number">50</span>m;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">add</span> <span class="keyword">standby</span> <span class="keyword">logfile</span> <span class="keyword">group</span> <span class="number">6</span> (<span class="string">'+DGDATA/etyyhis/standbylog/standby_group_06.log'</span>) <span class="keyword">size</span> <span class="number">50</span>m;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">add</span> <span class="keyword">standby</span> <span class="keyword">logfile</span> <span class="keyword">group</span> <span class="number">7</span> (<span class="string">'+DGDATA/etyyhis/standbylog/standby_group_07.log'</span>) <span class="keyword">size</span> <span class="number">50</span>m;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">add</span> <span class="keyword">standby</span> <span class="keyword">logfile</span> <span class="keyword">group</span> <span class="number">8</span> (<span class="string">'+DGDATA/etyyhis/standbylog/standby_group_08.log'</span>) <span class="keyword">size</span> <span class="number">50</span>m;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">add</span> <span class="keyword">standby</span> <span class="keyword">logfile</span> <span class="keyword">group</span> <span class="number">9</span> (<span class="string">'+DGDATA/etyyhis/standbylog/standby_group_09.log'</span>) <span class="keyword">size</span> <span class="number">50</span>m;</span><br><span class="line">假如需要删除日志</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">drop</span> <span class="keyword">logfile</span> <span class="keyword">group</span> <span class="number">5</span>;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">drop</span> <span class="keyword">logfile</span> <span class="keyword">group</span> <span class="number">6</span>;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">drop</span> <span class="keyword">logfile</span> <span class="keyword">group</span> <span class="number">7</span>;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">drop</span> <span class="keyword">logfile</span> <span class="keyword">group</span> <span class="number">8</span>;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">drop</span> <span class="keyword">logfile</span> <span class="keyword">group</span> <span class="number">9</span>;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">drop</span> <span class="keyword">logfile</span> <span class="keyword">group</span> <span class="number">10</span>;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">drop</span> <span class="keyword">logfile</span> <span class="keyword">group</span> <span class="number">11</span>;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">drop</span> <span class="keyword">logfile</span> <span class="keyword">group</span> <span class="number">12</span>;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">drop</span> <span class="keyword">logfile</span> <span class="keyword">group</span> <span class="number">13</span>;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">drop</span> <span class="keyword">logfile</span> <span class="keyword">group</span> <span class="number">14</span>;</span><br><span class="line">主库，RAC需要加两个thread，每个thread比在线日志多一组</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">add</span> <span class="keyword">standby</span> <span class="keyword">logfile</span> <span class="keyword">thread</span> <span class="number">1</span> <span class="keyword">group</span> <span class="number">5</span> (<span class="string">'+DGDATA/etyyhis/standbylog/standby_group_05.log'</span>) <span class="keyword">size</span> <span class="number">50</span>m;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">add</span> <span class="keyword">standby</span> <span class="keyword">logfile</span> <span class="keyword">thread</span> <span class="number">1</span> <span class="keyword">group</span> <span class="number">6</span> (<span class="string">'+DGDATA/etyyhis/standbylog/standby_group_06.log'</span>) <span class="keyword">size</span> <span class="number">50</span>m;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">add</span> <span class="keyword">standby</span> <span class="keyword">logfile</span> <span class="keyword">thread</span> <span class="number">1</span> <span class="keyword">group</span> <span class="number">7</span> (<span class="string">'+DGDATA/etyyhis/standbylog/standby_group_07.log'</span>) <span class="keyword">size</span> <span class="number">50</span>m;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">add</span> <span class="keyword">standby</span> <span class="keyword">logfile</span> <span class="keyword">thread</span> <span class="number">1</span> <span class="keyword">group</span> <span class="number">8</span> (<span class="string">'+DGDATA/etyyhis/standbylog/standby_group_08.log'</span>) <span class="keyword">size</span> <span class="number">50</span>m;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">add</span> <span class="keyword">standby</span> <span class="keyword">logfile</span> <span class="keyword">thread</span> <span class="number">1</span> <span class="keyword">group</span> <span class="number">9</span> (<span class="string">'+DGDATA/etyyhis/standbylog/standby_group_09.log'</span>) <span class="keyword">size</span> <span class="number">50</span>m;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">add</span> <span class="keyword">standby</span> <span class="keyword">logfile</span> <span class="keyword">thread</span> <span class="number">2</span> <span class="keyword">group</span> <span class="number">10</span> (<span class="string">'+DGDATA/etyyhis/standbylog/standby_group_10.log'</span>) <span class="keyword">size</span> <span class="number">50</span>m;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">add</span> <span class="keyword">standby</span> <span class="keyword">logfile</span> <span class="keyword">thread</span> <span class="number">2</span> <span class="keyword">group</span> <span class="number">11</span> (<span class="string">'+DGDATA/etyyhis/standbylog/standby_group_11.log'</span>) <span class="keyword">size</span> <span class="number">50</span>m;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">add</span> <span class="keyword">standby</span> <span class="keyword">logfile</span> <span class="keyword">thread</span> <span class="number">2</span> <span class="keyword">group</span> <span class="number">12</span> (<span class="string">'+DGDATA/etyyhis/standbylog/standby_group_12.log'</span>) <span class="keyword">size</span> <span class="number">50</span>m;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">add</span> <span class="keyword">standby</span> <span class="keyword">logfile</span> <span class="keyword">thread</span> <span class="number">2</span> <span class="keyword">group</span> <span class="number">13</span> (<span class="string">'+DGDATA/etyyhis/standbylog/standby_group_13.log'</span>) <span class="keyword">size</span> <span class="number">50</span>m;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">add</span> <span class="keyword">standby</span> <span class="keyword">logfile</span> <span class="keyword">thread</span> <span class="number">2</span> <span class="keyword">group</span> <span class="number">14</span> (<span class="string">'+DGDATA/etyyhis/standbylog/standby_group_14.log'</span>) <span class="keyword">size</span> <span class="number">50</span>m;</span><br></pre></td></tr></table></figure>

<ol start="7">
<li>启动备库日志应用</li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">startup nomount</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">mount</span> <span class="keyword">standby</span> <span class="keyword">database</span>;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">recover</span> <span class="keyword">managed</span> <span class="keyword">standby</span> <span class="keyword">database</span> <span class="keyword">using</span> <span class="keyword">current</span> <span class="keyword">logfile</span> <span class="keyword">disconnect</span> <span class="keyword">from</span> <span class="keyword">session</span>;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">recover</span> <span class="keyword">managed</span> <span class="keyword">standby</span> <span class="keyword">database</span>  <span class="keyword">disconnect</span> <span class="keyword">from</span> <span class="keyword">session</span>;</span><br></pre></td></tr></table></figure>

<ol start="8">
<li>启动ADG</li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">打开物理DG时查询功能(active dataguard)。</span><br><span class="line">SQL&gt; ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;</span><br><span class="line">SQL&gt; ALTER DATABASE OPEN;</span><br><span class="line">SQL&gt; select open_mode from v$database;</span><br><span class="line">OPEN_MODE</span><br><span class="line"><span class="comment">--------------------</span></span><br><span class="line">READ ONLY</span><br><span class="line">SQL&gt; ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT;</span><br><span class="line">SQL&gt; select open_mode from v$database;</span><br><span class="line">OPEN_MODE</span><br><span class="line"><span class="comment">--------------------</span></span><br><span class="line">READ ONLY <span class="keyword">WITH</span> <span class="keyword">APPLY</span></span><br><span class="line">也就是说，在正常启动 <span class="keyword">physical</span> <span class="keyword">standby</span> <span class="keyword">database</span>后，需要再执行几个语句，才能将<span class="keyword">physical</span> <span class="keyword">standby</span> <span class="keyword">database</span> 变为active dataguard状态</span><br></pre></td></tr></table></figure>

<ol start="9">
<li>修改主库的DG模式（最大性能模式）</li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> database_role,protection_mode,protection_level <span class="keyword">from</span> v$<span class="keyword">database</span>; <span class="comment">#查看当前保护模式</span></span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">set</span> <span class="keyword">standby</span> <span class="keyword">database</span> <span class="keyword">to</span> <span class="keyword">maximize</span> <span class="keyword">availability</span>; <span class="comment">#修改为最高可用模式</span></span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">set</span> <span class="keyword">standby</span> <span class="keyword">database</span> <span class="keyword">to</span> <span class="keyword">maximize</span> <span class="keyword">protection</span>; <span class="comment">#修改为最大保护模式</span></span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">set</span> <span class="keyword">standby</span> <span class="keyword">database</span> <span class="keyword">to</span> <span class="keyword">maximize</span> <span class="keyword">performance</span>; <span class="comment">#修改为最高性能模式</span></span><br><span class="line">1、最高性能模式既可以使用ARCH方式传递日志，也可以使用LGWR方式传递，在升级到更高级别保护模式时，需使用LGWR方式，且需要在备库创建standby日志组。</span><br><span class="line">2、三种保护模式进行切换时，最高性能升级到最大保护模式（⑤），需先把数据库重启到mounted状态才能操作。其他情况（①②③④⑥）相互切换时，可以直接进行。</span><br><span class="line">根据实验结论，在生产环境下如果需要从最高性能模式升级为最大保护模式，可先从最高性能模式升级最高可用模式，再由最高可用模式升级为最大保护模式。</span><br><span class="line">如下图，通过①②分步升级的方式代替⑤直接升级,避免了重启到mounted状态对生产环境下业务造成的影响。</span><br><span class="line">1.最大保护模式</span><br><span class="line">1）这种模式提供了最高级别的数据保护能力；</span><br><span class="line">2）要求至少一个物理备库收到重做日志后，主库的事务才能够提交；</span><br><span class="line">3）主库找不到合适的备库写入时，主库会自动关闭，防止未受保护的数据出现；</span><br><span class="line">4）优点：该模式可以保证备库没有数据丢失；</span><br><span class="line">5）缺点：主库的自动关闭会影响到主库的可用性，同时需要备库恢复后才能提交，对网络等客观条件要求非常的高，主库的性能会因此受到非常大的冲击。</span><br><span class="line">2.最大可用性模式</span><br><span class="line">1）该模式提供了仅次于"最大保护模式"的数据保护能力；</span><br><span class="line">2）要求至少一个物理备库收到重做日志后，主库的事务才能够提交；</span><br><span class="line">3）主库找不到合适的备库写入时，主库不会关闭，而是临时降低到"最大性能模式"模式，直到问题得到处理；</span><br><span class="line">4）优点：该模式可以在没有问题出现的情况下，保证备库没有数据丢失，是一种折中的方法；</span><br><span class="line">5）缺点：在正常运行的过程中缺点是主库的性能受到诸多因素的影响。</span><br><span class="line">3.最大性能模式</span><br><span class="line">1）该模式是默认模式，可以保证主数据库的最高可用性；</span><br><span class="line">2）保证主库运行过程中不受备库的影响，主库事务正常提交，不因备库的任何问题影响到主库的运行；</span><br><span class="line">4）优点：避免了备库对主数据库的性能和可用性影响；</span><br><span class="line">5）缺点：如果与主库提交的事务相关的恢复数据没有发送到备库，这些事务数据将被丢失，不能保证数据无损失；</span><br></pre></td></tr></table></figure>


<ol start="10">
<li>DG的监控</li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="keyword">sequence</span><span class="comment">#,applied,status from v$archived_log;#查看日志归档情况</span></span><br><span class="line"><span class="keyword">select</span> <span class="keyword">sequence</span><span class="comment">#,status from v$log; #主、备库查看当前日志状况</span></span><br><span class="line"><span class="keyword">select</span> process, <span class="keyword">sequence</span><span class="comment">#, status, delay_mins from v$managed_standby; #备库查看RFS接收日志和MRP应用日志同步主库情况</span></span><br><span class="line"><span class="keyword">select</span> archived_thread<span class="comment">#,archived_seq#,applied_thread#,applied_seq# from v$archive_dest_status; #查看主备同步情况</span></span><br><span class="line"><span class="keyword">select</span> <span class="keyword">status</span>,gap_status <span class="keyword">from</span> v$archive_dest_status <span class="keyword">where</span> dest_id=<span class="number">2</span>; <span class="comment">#查看是否有GAP,如果有GAP一定要及时检查解决</span></span><br><span class="line"><span class="keyword">select</span> * <span class="keyword">from</span> v$archive_gap; <span class="comment">#查看主备是否有gap</span></span><br><span class="line"><span class="keyword">select</span> <span class="keyword">thread</span><span class="comment">#,sequence#,first_change#,next_change# from v$log_history; #备库查看已经应用的归档</span></span><br><span class="line"><span class="keyword">select</span> REGISTRAR,CREATOR,<span class="keyword">THREAD</span><span class="comment">#,APPLIED,sequence#,first_change#,next_change#, COMPLETION_TIME from v$archived_log; #备库查看已经归档的日志</span></span><br><span class="line">监控 <span class="built_in">real</span>-<span class="built_in">time</span> <span class="keyword">apply</span> 实时同步的dataguard 是否正常同步：</span><br><span class="line"><span class="keyword">select</span> to_char(<span class="keyword">SYSDATE</span>,<span class="string">'yyyymmdd hh24:mi:ss'</span>) CTIME,<span class="keyword">NAME</span>,<span class="keyword">VALUE</span>,DATUM_TIME <span class="keyword">from</span> V$DATAGUARD_STATS <span class="keyword">WHERE</span> <span class="keyword">NAME</span> <span class="keyword">LIKE</span> <span class="string">'%lag'</span>;</span><br><span class="line">其中如果apply lag对应的value大于0，那么就需要注意检查是否同步正常。如果相差时间非常多，value值等于几分钟，甚至达到1个小时，那可能实时同步有问题，需要检查 alert log 文件，其中会提示是否启动了real time apply, 检查最近的log，可以发现：</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">recover</span> <span class="keyword">managed</span> <span class="keyword">standby</span> <span class="keyword">database</span> <span class="keyword">using</span> <span class="keyword">current</span> <span class="keyword">logfile</span> <span class="keyword">disconnect</span> <span class="keyword">from</span> <span class="keyword">session</span></span><br><span class="line">MRP0 started <span class="keyword">with</span> pid=<span class="number">20</span>, OS <span class="keyword">id</span>=<span class="number">647263927</span></span><br><span class="line"><span class="keyword">Managed</span> <span class="keyword">Standby</span> <span class="keyword">Recovery</span> <span class="keyword">starting</span> <span class="built_in">Real</span> <span class="built_in">Time</span> <span class="keyword">Apply</span></span><br></pre></td></tr></table></figure>

<ol start="11">
<li>数据同步验证</li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">主库创建表空间</span><br><span class="line"><span class="keyword">create</span> <span class="keyword">tablespace</span> <span class="keyword">user_data</span>  </span><br><span class="line"><span class="keyword">logging</span>  </span><br><span class="line"><span class="keyword">datafile</span> <span class="string">'+DGDATA'</span></span><br><span class="line"><span class="keyword">size</span> <span class="number">50</span>m  </span><br><span class="line"><span class="keyword">autoextend</span> <span class="keyword">on</span>  </span><br><span class="line"><span class="keyword">next</span> <span class="number">50</span>m <span class="keyword">maxsize</span> <span class="number">20480</span>m  </span><br><span class="line"><span class="keyword">extent</span> <span class="keyword">management</span> <span class="keyword">local</span>;  </span><br><span class="line">创建表</span><br><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> testid</span><br><span class="line">(</span><br><span class="line">username   <span class="built_in">varchar2</span>(<span class="number">60</span>),  </span><br><span class="line"><span class="keyword">id</span>         <span class="built_in">varchar2</span>(<span class="number">50</span>)  </span><br><span class="line">)</span><br><span class="line"><span class="keyword">tablespace</span> <span class="keyword">user_data</span>;</span><br><span class="line">插入数据</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> testid(username) <span class="keyword">values</span>(<span class="string">'aa'</span>);</span><br><span class="line"><span class="keyword">commit</span>;</span><br><span class="line">备库</span><br><span class="line"><span class="keyword">select</span> * <span class="keyword">from</span> testid;</span><br><span class="line">可以看到数据马上就同步过来了</span><br></pre></td></tr></table></figure>

<ol start="12">
<li>主备切换</li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line">查看状态</span><br><span class="line"><span class="keyword">select</span> open_mode,database_role,switchover_status <span class="keyword">from</span> v$<span class="keyword">database</span>;</span><br><span class="line">物理standby切换步骤:</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">recover</span> <span class="keyword">managed</span> <span class="keyword">standby</span> <span class="keyword">database</span> <span class="keyword">disconnect</span> <span class="keyword">from</span> <span class="keyword">session</span>; 开启MRP应用</span><br><span class="line"></span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">recover</span> <span class="keyword">managed</span> <span class="keyword">standby</span> <span class="keyword">database</span> <span class="keyword">cancel</span>;关闭MRP应用进程</span><br><span class="line"></span><br><span class="line">在主库执行切换至standby：</span><br><span class="line"><span class="keyword">ALTER</span> <span class="keyword">DATABASE</span> <span class="keyword">COMMIT</span> <span class="keyword">TO</span> <span class="keyword">SWITCHOVER</span> <span class="keyword">TO</span> <span class="keyword">PHYSICAL</span> <span class="keyword">STANDBY</span>;</span><br><span class="line">SHUTDOWN IMMEDIATE;</span><br><span class="line">STARTUP NOMOUNT;</span><br><span class="line"><span class="keyword">ALTER</span> <span class="keyword">DATABASE</span> <span class="keyword">MOUNT</span> <span class="keyword">STANDBY</span> <span class="keyword">DATABASE</span>;</span><br><span class="line">在备库执行切换至primary:</span><br><span class="line"><span class="keyword">ALTER</span> <span class="keyword">DATABASE</span> <span class="keyword">COMMIT</span> <span class="keyword">TO</span> <span class="keyword">SWITCHOVER</span> <span class="keyword">TO</span> PRIMARY;</span><br><span class="line">SHUTDOWN IMMEDIATE;</span><br><span class="line">STARTUP;</span><br><span class="line">在主库执行启动MRP:</span><br><span class="line"><span class="keyword">ALTER</span> <span class="keyword">DATABASE</span> <span class="keyword">RECOVER</span> <span class="keyword">MANAGED</span> <span class="keyword">STANDBY</span> <span class="keyword">DATABASE</span> <span class="keyword">DISCONNECT</span> <span class="keyword">FROM</span> <span class="keyword">SESSION</span>;</span><br><span class="line">如果主库DOWN机，我们可以在备库执行以下指令直接激活备库:</span><br><span class="line"><span class="keyword">Alter</span> <span class="keyword">DATABASE</span> <span class="keyword">RECOVER</span> <span class="keyword">MANAGED</span> <span class="keyword">STANDBY</span> <span class="keyword">DATABASE</span> <span class="keyword">FINISH</span>;</span><br><span class="line"><span class="keyword">Alter</span> <span class="keyword">DATABASE</span> <span class="keyword">COMMIT</span> <span class="keyword">TO</span> <span class="keyword">SWITCHOVER</span> <span class="keyword">TO</span> PRIMARY;</span><br><span class="line">SHUTDOWN IMMEDIATE;</span><br><span class="line">STARTUP;</span><br><span class="line">附一份DG主备库切换状态说明：</span><br><span class="line">v$database</span><br><span class="line">NOT ALLOWED - On a primary database, this status indicates that there are no valid and enabled standby databases. On a standby database, this status indicates that a switchover request has not been received from the primary database.</span><br><span class="line">SESSIONS ACTIVE - The database has active sessions. On a physical standby database, the <span class="keyword">WITH</span> <span class="keyword">SESSION</span> <span class="keyword">SHUTDOWN</span> <span class="keyword">SQL</span> clause must be specified <span class="keyword">to</span> perform a <span class="keyword">role</span> transition <span class="keyword">while</span> <span class="keyword">in</span> this state. <span class="keyword">On</span> a <span class="keyword">logical</span> <span class="keyword">standby</span> <span class="keyword">database</span>, a <span class="keyword">role</span> transition can be performed <span class="keyword">while</span> <span class="keyword">in</span> this state, but the <span class="keyword">role</span> transition will <span class="keyword">not</span> <span class="keyword">complete</span> <span class="keyword">until</span> <span class="keyword">all</span> <span class="keyword">current</span> transactions have committed.</span><br><span class="line"><span class="keyword">SWITCHOVER</span> PENDING - <span class="keyword">On</span> a <span class="keyword">physical</span> <span class="keyword">standby</span> <span class="keyword">database</span>, this <span class="keyword">status</span> indicates that a <span class="keyword">switchover</span> request has been received <span class="keyword">from</span> the primary <span class="keyword">database</span> <span class="keyword">and</span> <span class="keyword">is</span> being processed. A <span class="keyword">physical</span> <span class="keyword">standby</span> <span class="keyword">database</span> cannot <span class="keyword">switch</span> <span class="keyword">to</span> the primary <span class="keyword">role</span> <span class="keyword">while</span> <span class="keyword">in</span> this transient state.</span><br><span class="line"><span class="keyword">SWITCHOVER</span> LATENT - <span class="keyword">On</span> a <span class="keyword">physical</span> <span class="keyword">standby</span> <span class="keyword">database</span>, this <span class="keyword">status</span> indicates that a <span class="keyword">switchover</span> request was pending, but the original primary <span class="keyword">database</span> has been switched back <span class="keyword">to</span> the primary role.</span><br><span class="line"><span class="keyword">TO</span> PRIMARY - The <span class="keyword">database</span> <span class="keyword">is</span> ready <span class="keyword">to</span> <span class="keyword">switch</span> <span class="keyword">to</span> the primary role.</span><br><span class="line"><span class="keyword">TO</span> <span class="keyword">STANDBY</span> - The <span class="keyword">database</span> <span class="keyword">is</span> ready <span class="keyword">to</span> <span class="keyword">switch</span> <span class="keyword">to</span> either the <span class="keyword">physical</span> <span class="keyword">or</span> <span class="keyword">logical</span> <span class="keyword">standby</span> role.</span><br><span class="line"><span class="keyword">TO</span> <span class="keyword">LOGICAL</span> <span class="keyword">STANDBY</span> - The <span class="keyword">database</span> has received a <span class="keyword">data</span> dictionary <span class="keyword">from</span> a <span class="keyword">logical</span> <span class="keyword">standby</span> <span class="keyword">database</span> <span class="keyword">and</span> <span class="keyword">is</span> ready <span class="keyword">to</span> <span class="keyword">switch</span> <span class="keyword">to</span> the <span class="keyword">logical</span> <span class="keyword">standby</span> role.</span><br><span class="line"><span class="keyword">RECOVERY</span> NEEDED - <span class="keyword">On</span> a <span class="keyword">physical</span> <span class="keyword">standby</span> <span class="keyword">database</span>, this <span class="keyword">status</span> indicates that additional <span class="keyword">redo</span> must be applied <span class="keyword">before</span> the <span class="keyword">database</span> can <span class="keyword">switch</span> <span class="keyword">to</span> the primary role.</span><br><span class="line">PREPARING <span class="keyword">SWITCHOVER</span> - <span class="keyword">On</span> a primary <span class="keyword">database</span>, this <span class="keyword">status</span> indicates that a <span class="keyword">data</span> dictionary <span class="keyword">is</span> being received <span class="keyword">from</span> a <span class="keyword">logical</span> <span class="keyword">standby</span> <span class="keyword">database</span> <span class="keyword">in</span> preparation <span class="keyword">for</span> switching <span class="keyword">to</span> the <span class="keyword">logical</span> <span class="keyword">standby</span> role. <span class="keyword">On</span> a <span class="keyword">logical</span> <span class="keyword">standby</span> <span class="keyword">database</span>, this <span class="keyword">status</span> indicates that the <span class="keyword">data</span> dictionary has been sent <span class="keyword">to</span> the primary <span class="keyword">database</span> <span class="keyword">and</span> other <span class="keyword">standby</span> databases.</span><br><span class="line">PREPARING DICTIONARY - <span class="keyword">On</span> a <span class="keyword">logical</span> <span class="keyword">standby</span> <span class="keyword">database</span>, this <span class="keyword">status</span> indicates that the <span class="keyword">data</span> dictionary <span class="keyword">is</span> being sent <span class="keyword">to</span> the primary <span class="keyword">database</span> <span class="keyword">and</span> other <span class="keyword">standby</span> <span class="keyword">databases</span> <span class="keyword">in</span> preparation <span class="keyword">for</span> switching <span class="keyword">to</span> the primary role.</span><br><span class="line"><span class="keyword">FAILED</span> DESTINATION - <span class="keyword">On</span> a primary <span class="keyword">database</span>, this <span class="keyword">status</span> indicates that one <span class="keyword">or</span> more <span class="keyword">standby</span> destinations <span class="keyword">are</span> <span class="keyword">in</span> an <span class="keyword">error</span> state.</span><br><span class="line">RESOLVABLE GAP - <span class="keyword">On</span> a primary <span class="keyword">database</span>, this <span class="keyword">status</span> indicates that one <span class="keyword">or</span> more <span class="keyword">standby</span> <span class="keyword">databases</span> have a <span class="keyword">redo</span> gap that can be automatically resolved <span class="keyword">by</span> fetching the <span class="keyword">missing</span> <span class="keyword">redo</span> <span class="keyword">from</span> the primary <span class="keyword">database</span> <span class="keyword">or</span> <span class="keyword">from</span> another <span class="keyword">standby</span> database.</span><br><span class="line">UNRESOLVABLE GAP - <span class="keyword">On</span> a primary <span class="keyword">database</span>, this <span class="keyword">status</span> indicates that one <span class="keyword">or</span> more <span class="keyword">standby</span> <span class="keyword">databases</span> have a <span class="keyword">redo</span> gap that cannot be automatically resolved <span class="keyword">by</span> fetching the <span class="keyword">missing</span> <span class="keyword">redo</span> <span class="keyword">from</span> the primary <span class="keyword">database</span> <span class="keyword">or</span> <span class="keyword">from</span> another <span class="keyword">standby</span> database.</span><br><span class="line"><span class="keyword">LOG</span> <span class="keyword">SWITCH</span> GAP - <span class="keyword">On</span> a primary <span class="keyword">database</span>, this <span class="keyword">status</span> indicates that one <span class="keyword">or</span> more <span class="keyword">standby</span> <span class="keyword">databases</span> <span class="keyword">are</span> <span class="keyword">missing</span> <span class="keyword">redo</span> due <span class="keyword">to</span> a recent <span class="keyword">log</span> switch.</span><br></pre></td></tr></table></figure>

<ol start="13">
<li>关于延迟应用</li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">方法1: 在备库应用主库日志的语句中指定delay属性</span><br><span class="line">如<span class="keyword">alter</span> <span class="keyword">database</span> <span class="keyword">recover</span> <span class="keyword">managed</span> <span class="keyword">standby</span> <span class="keyword">database</span> delay <span class="number">120</span> <span class="keyword">disconnect</span> <span class="keyword">from</span> <span class="keyword">session</span>;   <span class="comment">--备库延迟120分钟应用主库日志</span></span><br><span class="line">方法2: log_ archive_dest_n参数中指定了delay属性</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">system</span> <span class="keyword">set</span> log_archive_dest_2=<span class="string">'service=etyyhisdg lgwr sync delay=120 valid_for=(all_logfiles,all_roles) db_unique_name=etyyhisdg'</span>;</span><br></pre></td></tr></table></figure>

<ol start="14">
<li>清理过期的归档日志</li>
</ol>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">crosscheck archivelog all;                             <span class="comment">---&gt;校验日志的可用性</span></span><br><span class="line">list expired archivelog all;                           <span class="comment">---&gt;列出所有失效的归档日志</span></span><br><span class="line"><span class="keyword">delete</span> <span class="keyword">archivelog</span> <span class="keyword">until</span> <span class="keyword">sequence</span> <span class="number">16</span>;                   <span class="comment">---&gt;删除log sequence为16及16之前的所有归档日志</span></span><br><span class="line"><span class="keyword">delete</span> <span class="keyword">archivelog</span> <span class="keyword">all</span> completed <span class="keyword">before</span> <span class="string">'sysdate-7'</span>;    <span class="comment">---&gt;删除系统时间7天以前的归档日志，不会删除闪回区有效的归档日志</span></span><br><span class="line"><span class="keyword">delete</span> <span class="keyword">archivelog</span> <span class="keyword">all</span> completed <span class="keyword">before</span> <span class="string">'sysdate - 1'</span>;  <span class="comment">---&gt;同上，1天以前的</span></span><br><span class="line"><span class="keyword">delete</span> <span class="keyword">archivelog</span> <span class="keyword">from</span> <span class="built_in">time</span> <span class="string">'sysdate-1'</span>;               <span class="comment">---&gt;注意这个命令，删除系统时间1天以内到现在的归档日志</span></span><br><span class="line"><span class="keyword">delete</span> <span class="keyword">noprompt</span> <span class="keyword">archivelog</span> <span class="keyword">all</span> completed <span class="keyword">before</span> <span class="string">'sysdate'</span>;   <span class="comment">---&gt;该命令清除所有的归档日志</span></span><br><span class="line"><span class="keyword">delete</span> <span class="keyword">noprompt</span> <span class="keyword">archivelog</span> <span class="keyword">all</span>;                              <span class="comment">---&gt;同上一命令</span></span><br></pre></td></tr></table></figure>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/oracle-%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/" rel="tag"># oracle 安装部署</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/05/27/2019-07-17-NBU%E5%BC%82%E6%9C%BA%E6%81%A2%E5%A4%8D/" rel="prev" title="NBU异机恢复">
      <i class="fa fa-chevron-left"></i> NBU异机恢复
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/05/27/2019-07-17-ORACLE%2011G%20RAC(Virtualbox&&Oracle%20Linux%207)/" rel="next" title="ORACLE 11G RAC(Virtualbox&&Oracle Linux 7)">
      ORACLE 11G RAC(Virtualbox&&Oracle Linux 7) <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Emoh"
      src="/images/touxiang.png">
  <p class="site-author-name" itemprop="name">Emoh</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">29</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">16</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">23</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Emoh</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

</body>
</html>
